//
//  NoInfoPromtView.m
//  QRMaster
//
//  Created by myApple on 16/4/29.
//  Copyright © 2016年 myApple. All rights reserved.
//

#import "NoInfoPromtView.h"
#import "AutoLayoutFrame.h"

@interface NoInfoPromtView()
{
    UILabel * promtLabel;
    UIImageView * promtView;
}
@end

@implementation NoInfoPromtView

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
        self.backgroundColor = UIColorFromRGB(0xebebeb);
        promtView = [[UIImageView alloc] init];
        [self addSubview:promtView];
        
        promtLabel = [[UILabel alloc] init];
        promtLabel.adjustsFontSizeToFitWidth = YES;
        promtLabel.font = [UIFont systemFontOfSize:15.0];
        promtLabel.textAlignment = NSTextAlignmentCenter;
        promtLabel.numberOfLines = 2;
        promtLabel.textColor = UIColorFromRGB(0x727272);
        [self addSubview:promtLabel];
    }
    return self;
}

-(void)prepareViewWith:(NSString *)imageName withPromt:(NSString *)string
{
//    if (imageName == nil || [imageName isEqualToString:@""]) {
//        promtView.hidden = YES;
//    }
//    NSString * path = [[NSBundle mainBundle]pathForResource:@"" ofType:@"png"];
//    UIImage * image = [UIImage imageWithContentsOfFile:path];
//    float width = image.size.width;
//    float height = image.size.height;
//    float x = (UI_SCREEN_WIDTH - width) / 2.0 + 20;
//    float y = (self.frame.size.height - image.size.height) / 2.0 - 50;
//    promtView.frame = CGRectMake(x, y, width, height);
//    
//    x = 40;
//    width = self.frame.size.width - 2 * x;
//    y = promtView.frame.size.height + promtView.frame.origin.y + 20;
//    height = 40;
//    promtLabel.frame = CGRectMake(x, y, width, height);
//    
//    promtView.image = [UIImage imageWithContentsOfFile:path];
//    promtLabel.text = string;
//    UITapGestureRecognizer * refreshTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(refreshClick)];
//    [self addGestureRecognizer:refreshTap];
    
    if (imageName == nil || [imageName isEqualToString:@""]) {
        promtView.hidden = YES;
    }
    promtView.frame = CGRectMake((UI_SCREEN_WIDTH-110)/2, UI_SCREEN_HEIGHT*0.22, 110, 120);
    promtView.image = [UIImage imageNamed:imageName];
    promtLabel.frame = CGRectMake((UI_SCREEN_WIDTH-110)/2, promtView.frame.origin.y+120+34, 110, 40);
    promtLabel.text = string;
    UITapGestureRecognizer * refreshTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(refreshClick)];
    [self addGestureRecognizer:refreshTap];
}


-(void)prepareViewWithPromtTitle:(NSString *)title
{
    NSString * path = @"noInformationImage";
    float width = 110;
    float height = 120;
    float x = (UI_SCREEN_WIDTH - width) / 2.0;
    float y = [AutoLayoutFrame autoSizeY:200];
    promtView.frame = CGRectMake(x, y, width, height);
    
    x = 22;
    width = self.frame.size.width - 2 * x;
    y = promtView.frame.size.height + promtView.frame.origin.y + [AutoLayoutFrame autoSizeY:34];
    height = 40;
    promtLabel.frame = CGRectMake(x, y, width, height);
    promtView.image = [UIImage imageNamed:path];
    promtLabel.text = title;
    UITapGestureRecognizer * refreshTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(refreshClick)];
    [self addGestureRecognizer:refreshTap];
}

-(void)refreshClick
{
    DDLOG(@"刷新");
    if (_delegate && [_delegate respondsToSelector:@selector(clickRefresh)]) {
        [_delegate clickRefresh];
    }
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
